package edu.scau.divineplace.controller;

import edu.scau.divineplace.config.global.log.WebLog;
import edu.scau.divineplace.entity.dos.MusicDiscListDO;
import edu.scau.divineplace.entity.dos.UserDO;
import edu.scau.divineplace.entity.vo.FavoriteUserVO;
import edu.scau.divineplace.service.FavoriteService;
import edu.scau.divineplace.service.MusicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Author: x1aolone
 * @Date: 2020/12/11 15:47
 */
@Slf4j
@RestController
@CrossOrigin
@Api("Favorite控制器")
@WebLog("Favorite控制器")
@Validated
@RequestMapping("/favorite")
public class FavoriteController {

    @Autowired
    private FavoriteService favoriteService;

    @ApiOperation("通过内容id获取收藏该内容的用户列表")
    @GetMapping("/user/list/{contentId}")
    public List<FavoriteUserVO> listFavoriteUser(@PathVariable Long contentId, Integer currentPage, Integer pageSize){
        return favoriteService.listFavoriteUser(contentId, currentPage, pageSize);
    }

    @ApiOperation("通过内容id和用户id判断用户有没有收藏")
    @GetMapping("/judge")
    public boolean judgeFavorite(@NotNull Long userId, @NotNull Long contentId){
        return favoriteService.judge(userId, contentId);
    }

    @ApiOperation("用户收藏内容")
    @PostMapping("")
    public void add(@NotNull Long userId, @NotNull Long contentId, @NotNull Integer type){
        favoriteService.add(userId, contentId, type);
    }


    @ApiOperation("用户更新收藏内容的收藏类型")
    @PutMapping("")
    public void update(@NotNull Long userId, @NotNull Long contentId,@NotNull Integer type){
        favoriteService.update(userId, contentId, type);
    }

    @ApiOperation("用户取消收藏内容")
    @DeleteMapping("")
    public void delete(Long userId, Long contentId){
        favoriteService.delete(userId, contentId);
    }

    @ApiOperation("用户取消收藏内容")
    @DeleteMapping("/{favoriteId}")
    public void delete(@PathVariable Long favoriteId){
        favoriteService.delete(favoriteId);
    }

}
